// 我的审批
import React from 'react';
import './myReview.scss';
import BreadcrumbNav from '../../../component/breadcrumb/breadcrumb'
import { Row, Col, Space, Checkbox , Pagination, Calendar, Table  } from 'antd';
import cookie from 'react-cookies'
import { EditOutlined, DeleteOutlined ,SettingOutlined,LoadingOutlined, PlusOutlined ,UploadOutlined} from '@ant-design/icons';
import {applyList} from '../../../api/myWork'


class myReview extends React.Component {
	state = {
		apply_list: [],
	}
	componentWillMount(){
		this.columns = [
			{
                title: '#',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                render: (text,record,index) => `${index+1}`,
            },
			
			{
				title: '申报类型',
				dataIndex: 'apply_type',
				key: 'apply_type',
				render:(apply_type)=>{
					if(apply_type == 1){
						return <span>设备型号新增</span>
					} else {
						return <span>项目创建</span>
					}
				}
			},
			{
				title: '涉及项目',
				key: 'relative_remark',
				dataIndex: 'relative_remark',
			},
			{
				title: '申报人',
				dataIndex: 'create_u_name',
				key: 'create_u_name',
			},
			
			{
				title: '审批状态',
				key: 'state',
				dataIndex: 'state',
				render:(state)=>{
					if(state == 1){
						return <span>审批中</span>
					} else if(state == 2) {
						return <span>审批成功</span>
					} else {
						return <span>审批失败</span>
					}
				}
			},
			{
				title: '最后提交时间',
				key: 'last_sub_time',
				dataIndex: 'last_sub_time'
			},
			{
			  title: '操作',
			  key: 'action',
			  render: (text, record) => (
				<Space size="middle">
					<a style={{ marginRight:'6px', color:'#2F3CF2'}} className="link" onClick={this.toAddNewPro.bind(this, text)}>查看详情</a>
				</Space>
			  ),
			},
		];
    }
	componentDidMount() {
		this.getData()
	}
	// 获取数据
	getData = () => {
		let post_data = {
            auth_token:cookie.load('station_console_setting_web_login').auth_token,
			'type':'2'
        } 
		applyList(post_data).then(res => {
			this.setState({
				apply_list:res.data.apply_list
			})
        })
	}
    // "apply_type": 1, //类型 1设备型号新增 2项目创建
    toAddNewPro = (val) => {
		console.log(val, '看一下全部');
		if(val.apply_type == 1) {
			if(val.state == 2 || val.state == 3){
				// window.location.href=`/index/deviceLibrary/deviceInfo?apply_type=${val.apply_type}&relative_id=${val.relative_id}&suc=suc&approvalAndDeclaration=approvalAndDeclaration`
				this.props.history.push({
					pathname: '/index/deviceLibrary/deviceList/deviceInfo',
					state:{ apply_type:val.apply_type, relative_id:val.relative_id,suc:'suc',approvalAndDeclaration:'approvalAndDeclaration'}})
			} else {
				this.props.history.push({
					pathname: '/index/deviceLibrary/deviceList/deviceInfo',
					state:{ apply_type:val.apply_type, relative_id:val.relative_id,approvalAndDeclaration:'approvalAndDeclaration'}})
				// window.location.href=`/index/deviceLibrary/deviceInfo?apply_type=${val.apply_type}&relative_id=${val.relative_id}&approvalAndDeclaration=approvalAndDeclaration`
			}
		} else {
			window.location.href=`/index/hardwareCenter/programConfig#/programConfigDetail?id=${val.relative_id}&type=${2}&state=${val.state}`
		}
    }
	render() {
        const {apply_list } = this.state;
		return (
            <Row className="myReview" id="ContentMainList">

                        <Col span={24} className="myReview_son">
                        <Col span={24}>
							<div style={{height:'100px',margin:'30px'}} >
								<BreadcrumbNav />
							</div>
                            <div className="titleInfo" >
                                <div></div>
                                <div><span onClick={this.tofmywsb}>我的审批</span></div>
                            </div>
                            <div className="un_tableinfo">
								<Table  dataSource={apply_list}  columns={ this.columns}  pagination={false} locale={{emptyText: '暂无数据'}}></Table>    
							</div>
                        </Col>
						</Col>
			</Row>
		)
	}
}
export default myReview;